import Compost from "@/modal/Compost";
import {reactive} from "vue";
import Action from "@/modal/Action";

const action = reactive(Action.getInstance())
const compost = reactive(Compost.getInstance())
export default class Board {
  public market: Board = Market.getInstance();
  public Turn: Board = Turn.getInstance();
  public Area: Board = Area.getInstance();
  // 单例模式
  private static board: Board | null = null;

  public static createBoard(): Board {
    if (this.board === null) {
      this.board = new Board();
    }
    return this.board
  }
}

export class Market extends Board {

  private static instance: Market | null = null;

  public static getInstance(): Market {
    if (this.instance === null) {
      this.instance = new Market();
    }
    return this.instance
  }

  switchStep(step: number) {
    return step < 4 ? 0 : step < 20 ? 1 : step < 35 ? 2 : step < 50 ? 3 : step < 70 ? 4 : 5
  }

  reward(steps: number) {
    const type = this.switchStep(steps)
    switch (type) {
      case 0:
        compost.collectCompost(1);
        break;
      case 1:
        compost.collectCompost(1);
    }
  }
}

export class Turn extends Board {
  private static instance: Turn | null = null;

  public static getInstance(): Turn {
    if (this.instance === null) {
      this.instance = new Turn();
    }
    return this.instance
  }
}

export class Area extends Board {
  private static instance: Area | null = null;

  public static getInstance(): Area {
    if (this.instance === null) {
      this.instance = new Area();
    }
    return this.instance
  }
}